"""
model name : aihw
file       : randmap.py
information:
    author : OuYang
    time   : 2025/10/10
"""

import random
from utils.utils import corr2index


class RandMap:
    def __init__(self, left: int, right: int, s=None, e=None, walls=10, col=19, row=19):
        self.left = left
        self.right = right

        if s is None:
            s = (1, 1)

        if e is None:
            e = (col, row)
        self.s = s
        self.e = e

        assert walls < col * row - (col + row)
        self.walls = walls
        self.col = col
        self.row = row

    def rand(self):
        rand_map = [[random.randint(self.left, self.right) for _ in range(self.col)] for _ in range(self.row)]

        for _ in range(self.walls):
            (i, j) = random.randint(0, self.col - 1), random.randint(0, self.row - 1)
            rand_map[i][j] = -1

        si, sj = corr2index(self.s[0], self.s[1])
        ei, ej = corr2index(self.e[0], self.e[1])
        rand_map[si][sj] = 0
        rand_map[ei][ej] = 0
        return rand_map
